Repository navigation
fix(auth): create missing UserOptions for OAuth users - #1012
Merged
Merged
Conversation
Owner
|
Thx for this pr. Can you fix the lint issue. You can probably just run |
Owner
|
⭐ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users created through OAuth / Better Auth do not get a corresponding
UserOptionsrecord.The regular ZTNet registration flow creates
UserOptionstogether with the user, but the Better Auth user creation flow only creates theUserrecord.As a result,
auth.memay receive:and then fail on:
with:
This breaks the user settings/profile UI for OAuth-created users even though the OAuth session itself contains the correct user data.
Fix
This PR addresses both new and existing OAuth users:
databaseHooks.user.create.afterhook to createUserOptionsafter Better Auth creates a user;upsertso the hook is idempotent;auth.methat creates missingUserOptionsfor users created before this fix;localControllerUrlbehavior consistent with the regular registration flow.Result
New OAuth users now get a valid
UserOptionsrecord during creation.Existing OAuth users with missing
UserOptionsare automatically repaired on the nextauth.merequest.No database migration is required because the
UserOptionsmodel anduserIdrelation already exist.Testing
Tested with an OAuth user created through Microsoft Entra ID.
Before the fix:
After the fix:
UserOptionsis created;auth.mereturns successfully;